﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace GiveAQuiz.Common
{

  public class ViewCommand : ICommand
  {
    readonly Action _execute = null;
    readonly Func<bool> _canExecute = null;

    public ViewCommand(Action execute)
      : this(execute, null)
    {
    }

    public ViewCommand(Action execute, Func<bool> canExecute)
    {
      if (execute == null) throw new ArgumentNullException("execute");

      _execute = execute;
      _canExecute = canExecute;
    }

    public bool CanExecute(object parameter)
    {
      return _canExecute == null ? true : _canExecute();
    }

    public event EventHandler CanExecuteChanged;

    public void Execute(object parameter)
    {
      _execute();
    }

    public void RaiseCanExecuteChanged()
    {
      if (CanExecuteChanged != null)
      {
        CanExecuteChanged(this, new EventArgs());
      }
    }
  }
}
